package helper;

import java.text.DecimalFormat;
import java.util.*;

/**
 * This is the helper class to get ranges of parameters
 *
 * @author Eugene Khoroshutin
 *         Date: 12/23/12
 *         Time: 6:20 PM
 */


public class ParameterRanger {
    /**
     * Returns ArrayList of Integers within specific range, incremented by step
     * Please, note that MAX_VALUE is not included in the resulting range
     *
     * @param from start point
     * @param step step
     * @param to   end point
     * @return ArrayList of Integers
     */
    public static List<Integer> getRangeByStep(int from, int step, int to) {
        List<Integer> result = new ArrayList<Integer>();
        int stepsCount = from;
        int elementsInRange = (to - from) / step;
        for (int i = 0; i < elementsInRange; i++) {
            result.add(stepsCount);
            stepsCount += step;
        }
        return result;
    }

    /**
     * Returns ArrayList of Integers within specific range by the number of elements in range
     * Please, note that MAX_VALUE is not included in the resulting range
     *
     * @param from
     * @param to
     * @param elementsInRange
     * @return
     */
    public static List<Integer> getRangeByNumberOfElements(int from, int to, int elementsInRange) {
        List<Integer> result = new ArrayList<Integer>();
        int stepsCount = from;
        int step = (to - from) / elementsInRange;
        for (int i = 0; i < elementsInRange; i++) {
            result.add(stepsCount);
            stepsCount += step;
        }
        return result;
    }

    /**
     * Returns ArrayList of Doubles within specific range, incremented by step
     * Please, note that MAX_VALUE is not included in the resulting range
     *
     * @param from
     * @param to
     * @param step
     * @return
     */
    public static List<Double> getRangeByStep(Double from, Double step, Double to) {
        List<Double> result = new ArrayList<Double>();
        Double elementsInRange = (to - from) / step;
        Double stepsCount = from;
        for (int i = 0; i < elementsInRange; i++) {
            result.add(stepsCount);
            stepsCount += step;
        }
        return result;
    }

    /**
     * Returns ArrayList of Doubles within specific range by number of elements
     * Please, note that MAX_VALUE is not included in the resulting range
     *
     * @param from
     * @param to
     * @param elementsInRange
     * @return
     */
    public static List<Double> getRangeByNumberOfElements(Double from, Double to, int elementsInRange) {
        List<Double> result = new ArrayList<Double>();
        Double step = (to - from) / elementsInRange;
        Double stepsCount = from;
        for (int i = 0; i < elementsInRange; i++) {
            result.add(stepsCount);
            stepsCount += step;
        }
        return result;
    }

    /**
     * Returns range of Doubles with regard to the specified relative value
     *
     * @param relValue
     * @param multiplierMin
     * @param step
     * @param multiplierMax
     * @return
     */
    public static List<Double> getRelativeRangeByStep(Double relValue, Double multiplierMin, Double step, Double multiplierMax) {
        List<Double> result = new ArrayList<Double>();
        Double multiplier = multiplierMin;
        Double unroundedResult;
        Double roundedResult;
        for (int i = 0; i < (multiplierMax - multiplierMin) / step; i++) {
            unroundedResult = relValue * multiplier;
            roundedResult = Math.round(unroundedResult * 100.0) / 100.0;
            result.add(roundedResult);
            multiplier += step;
        }
        return result;
    }

    /**
     * Returns range of Doubles with regard to the specified relative value
     *
     * @param relValue
     * @param multiplierMin
     * @param numberOfElements
     * @param multiplierMax
     * @return
     */
    public static List<Double> getRelativeRangeByNumberOfElements(Double relValue, Double multiplierMin, Double multiplierMax, int numberOfElements) {
        List<Double> result = new ArrayList<Double>();
        Double multiplier = multiplierMin;
        Double unroundedResult;
        Double roundedResult;
        Double step = (multiplierMax - multiplierMin) / numberOfElements;
        for (int i = 0; i < numberOfElements; i++) {
            unroundedResult = relValue * multiplier;
            roundedResult = Math.round(unroundedResult * 100.0) / 100.0;
            result.add(roundedResult);
            multiplier += step;
        }
        return result;
    }
}


